package com.appspot.seqpop.controller;

import java.io.OutputStream;

import net.arnx.jsonic.JSON;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;

public abstract class SeqpopController extends Controller {

    @Override
    protected Navigation handleError(Throwable error) throws Throwable {
        requestScope("message", error.getMessage());
        return forward("/error.jsp");
    }

    protected void output(Object data) throws Exception {
        this.response.setContentType("application/json");
        OutputStream out = null;
        try {
            out = this.response.getOutputStream();
            JSON.encode(data, out);
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
        finally {
            if (out != null) {
                out.close();
            }
        }
    }
}
